package com.cskaoyan.controller.admin.marketmanagement;


import com.cskaoyan.bean.MarketOrder;
import com.cskaoyan.bean.bo.admin.order.*;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.admin.order.OrderDetailVo;
import com.cskaoyan.service.admin.order.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Aaliyah
 * @date 2022/9/7 9:20
 * @description: 处理订单管理模块的请求
 */
@RequestMapping("admin/order")
@RestController
public class OrderController {

    @Autowired
    OrderService orderService;


    /**
     * @description: /admin/order/list 请求的处理
     * @date: 2022/9/7 9:24
     * @param: [orderListBO] 封装了筛选条件和分页信息
     */
    @RequestMapping("list")
    public BaseRespVo<CommonData<MarketOrder>> orderList(OrderListBo orderListBo){
        return BaseRespVo.ok(orderService.orderList(orderListBo));
    }

    /**
     * @description: /admin/order/detail 请求的处理
     * @date: 2022/9/7 16:41
     * @param: [id] 从请求中接收的参数 订单id
     */
    @RequestMapping("detail")
    public BaseRespVo<OrderDetailVo> orderDetail(Integer id){
        return BaseRespVo.ok(orderService.orderDetail(id));
    }

    /**
     * @description: admin/order/refund 请求的处理
     * @date: 2022/9/8 16:03
     * @param: [orderRefundBo] 封装了订单id和退款金额
     */
    @RequestMapping("refund")
    public BaseRespVo orderRefund(@RequestBody OrderRefundBo orderRefundBo) {
        orderService.orderRefund(orderRefundBo);
        return BaseRespVo.ok(null);
    }

    /**
     * @description: /admin/order/ship 请求的处理
     * @date: 2022/9/8 16:39
     * @param: [orderShipBo] 封装了订单id 快递公司和快递单编号
     */
    @RequestMapping("ship")
    public BaseRespVo orderShip(@RequestBody OrderShipBo orderShipBo) {
        orderService.orderShip(orderShipBo);
        return BaseRespVo.ok(null);
    }

    /**
     * @description: /admin/order/channel 请求的处理
     * @date: 2022/9/13 1:18
     * @param: []
     */
    @RequestMapping("channel")
    public BaseRespVo orderChannel(){
        return BaseRespVo.ok(orderService.orderChannel());
    }

    @RequestMapping("delete")
    public BaseRespVo orderDelete(@RequestBody OrderIdBo orderIdBo){
        int code = orderService.orderDelete(orderIdBo);
        if (code == 200) {
            return BaseRespVo.ok(null);
        }
        BaseRespVo<Object> respData = new BaseRespVo<>();
        respData.setErrmsg("订单不能删除");
        respData.setErrno(623);
        return respData;
    }

    @RequestMapping("reply")
    public BaseRespVo orderReply(@RequestBody OrderReplyBo orderReplyBo){
        if (orderService.orderReply(orderReplyBo) == 200) {
            return BaseRespVo.ok(null);
        }
        BaseRespVo<Object> respData = new BaseRespVo<>();
        respData.setErrmsg("订单已回复！");
        respData.setErrno(622);
        return respData;
    }

}
